<template>
	<view class="current">
		<view class="top-cj">
			<view class="bj">
			</view>
			<view class="hydj">
				<view class="left">
					<view class="">
						黄金会员
					</view>
					<view class="vipNaw">
						{{level==1?'当前等级':'未解锁'}}
					</view>
				</view>
				<view class="right">
					<view class="">
						钻石会员
					</view>
					<view class="vipNaw">
						{{level==2?'当前等级':'未解锁'}}
					</view>
				</view>
			</view>
		</view>
		<view class="memPri">
			<view class="memBg">
				<image :src="level==2?src2:src1" mode="aspectFill"></image>
			</view>
			<view class="vimData" :style="{color:(level==2?'#fff':'#F9D8A1')}">
				<view class="vipmc">
					{{level==0?'普通会员':level==1?'黄金会员':'钻石会员'}}
				</view>
				<view class="vipxq">
					会员有效期
				</view>
				<view class="viptime" v-if="level==2||level==1">
					<!-- {{myData.start_time}}-{{myData.end_time}} -->
					{{myData.end_time}}
				</view>

			</view>
		</view>
		<view class="vipqy">
			<view class="top">
				会员权限
			</view>
			<view class="list">
				<view class="item item1">
					<view class="item-img">
						<image src="../../static/my/Vector.png" mode=""></image>
					</view>
					<view class="">
						发布置顶
					</view>
				</view>
				<view class="item item2">
					<view class="item-img">
						<image src="../../static/my/Vector.png" mode=""></image>
					</view>
					<view class="">
						求购置顶
					</view>
				</view>
				<view class="item item3">
					<view class="item-img">
						<image src="../../static/my/Vector.png" mode=""></image>
					</view>
					<view class="">
						会员特惠
					</view>

				</view>
			</view>
		</view>
		<u-button class="custom-style" shape="circle" text="充值会员"
			customStyle="background-color: #C8BAD5;color:#fff;margin-top:30rpx;width: 30%;" @click="goVip"></u-button>

		<u-popup :show="showPop" mode="bottom" @close="close" height="500rpx">
			<view class="p-3">
				<scroll-view scroll-y="false" style="height: 400rpx;">
					<u-radio-group v-model="radiovalue1" placement="row" style="justify-content: center;">
						<u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist1" :key="index"
							:label="item.name" :name="item.name" @change="radioChange(item)" activeColor="#3A384D"
							inactiveColor="C8BAD5" :value="item.value">
						</u-radio>
					</u-radio-group>
					<view class="" style="margin-top: 30px;color: #979797;">
						温馨提示：{{sysConfig.member_list[0].name}}需要花费{{sysConfig.member_list[0].price}}元，享有{{sysConfig.member_list[0].day}}天，
						{{sysConfig.member_list[1].name}}需要花费{{sysConfig.member_list[1].price}}元，享有{{sysConfig.member_list[1].day}}天。
					</view>
				</scroll-view>
				<view class="f-row jc-sb">
					<view style="width: 40%;">
						<u-button text="取消" type='info' @click='refuse'
							customStyle="background-color: #C8BAD5;color:#fff;border-color: #C8BAD5;"></u-button>
					</view>
					<view style="width: 40%;">
						<u-button text="充值" type='primary' @click="submit"
							customStyle="background-color: #3A384D;color:#fff;border-color: #3A384D;"></u-button>
					</view>
				</view>
			</view>
		</u-popup>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	// import memPri from '../../static/my/memPri.png'
	import hj_bj from '../../static/my/hj_bj.png'
	import zs_bj from '../../static/my/zs_bj.png'
	import {
		myMember,
		weChatPay,
		systemConfig,
		getUser,
	} from '@/request/api.js'
	export default {
		data() {
			return {
				list: {
					page: '1'
				},
				level: 0, //默认为普通会员
				sysConfig: null, //配置信息
				info: null, //个人信息
				showPop: false,
				src1: hj_bj,
				src2: zs_bj,
				myData: {
					start_time: '',
					end_time: ''
				},
				formData: {
					amount: '',
					type: 2,
					f_id: ''
				},
				radiolist1: [{
						name: '黄金会员',
						value: '1',
						disabled: false
					},
					{
						name: '钻石会员',
						value: '2',
						disabled: false
					},
				],
				radiovalue1: '黄金会员'
			};
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.getList()
			this.getConfig()
			this.getUser()
		},
		methods: {
			submit() {
				// console.log(this.radiovalue1)

				this.sysConfig.member_list.forEach(item => {
					if (item.name == this.radiovalue1) {
						this.formData.amount = item.price
						this.formData.f_id = item.id
					}
				})
				let self = this
				weChatPay(this.formData).then(res => {
					uni.requestPayment({
						"timeStamp": res.data.timeStamp,
						"nonceStr": res.data.nonceStr,
						"package": res.data.package,
						"signType": "MD5",
						"paySign": res.data.paySign,
						success: (res) => {
							self.showPop = false
							uni.navigateTo({
								url: '/my_pages/components/success?title=充值会员已成功'
							})
							self.getList()
							self.getConfig()
							self.getUser()
						}, // 支付成功
						fail: (err) => {}, // 支付失败
					})
				})
			},
			radioChange(e) {
				// console.log(e)
			},
			goVip() {
				if (this.myData.lvl == 1 || this.myData.lvl == 2) {
					this.$refs.uToast.show({
						type: 'error',
						title: '您现在已经是会员，请过期后再充值',
						message: "您现在已经是会员，请过期后再充值",
					})
					return false
				}
				this.showPop = true
			},
			getList() {
				myMember(this.list).then(res => {
					this.myData = res.data
					this.level = res.data.lvl
					console.log(this.level)
				})
			},
			getConfig() {
				systemConfig().then(res => {
					// console.log(res)
					this.sysConfig = res.data
				})
			},
			getUser() {
				getUser().then(res => {
					// console.log(res)
					this.info = res.data
					// this.level = res.data.level

				})
			},
			refuse() {
				this.showPop = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-radio-group {
		justify-content: center !important;
	}

	.current {
		background: linear-gradient(#413F52, rgb(22, 21, 44));
		height: 100vh;
		width: 100vw;
		color: white;
		font-size: 30rpx;

		.vipqy {
			color: #F9D8A2;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			border: 1px solid;
			margin: 0px 20px;

			.top {
				width: 100%;
				text-align: center;
				padding: 23rpx 0px;
				border-bottom: 1px solid;
			}

			.list {
				display: flex;
				width: 100%;

				.item {
					.item-img {
						image {
							height: 20px;
							width: 20px;
						}
					}
				}

				.item1 {
					text-align: center;
					padding: 29rpx 0;
					border-right: 1px solid;
					width: 33%;
				}

				.item2 {
					text-align: center;
					padding: 29rpx 0;
					border-right: 1px solid;
					width: 33%;
				}

				.item3 {
					text-align: center;
					padding: 29rpx 0;
					width: 33%;
				}

			}
		}

		.memPri {
			margin-top: 120rpx;
			width: 100%;
			overflow: hidden;
			display: table;
			vertical-align: middle;
			text-align: center;
			position: relative;
			height: 240px;

			.memBg {
				padding: 15px 20px;

				image {
					height: 200px;
					width: 100%;
					border-radius: 32rpx;
				}
			}

			.vimData {
				color: #F9D8A1;
				position: absolute;
				top: 15px;
				margin-left: 9%;
				text-align: left;

				.vipmc {
					margin-top: 15px;
				}

				.vipxq {
					margin-top: 190rpx;
				}

				.viptime {
					margin-top: 10rpx;
				}
			}
		}

		// background-image: url(bj);
		// background-size: cover;
		// background-repeat: no-repeat;
		.top-cj {
			display: flex;
			flex-direction: column;
			padding-top: 50px;

			.bj {
				height: 38px;
				width: 50%;
				background-image: url('../../static/my/2.png');
				background-size: contain;
				background-repeat: no-repeat;
			}

			.hydj {
				position: relative;
				width: 50%;

				.vipNaw {
					font-size: 24rpx;
				}

				.left {
					position: absolute;
					bottom: -35px;
					left: 22%;
					text-align: center;
				}

				.right {
					position: absolute;
					bottom: -35px;
					right: 0;
					text-align: center;
				}
			}

		}
	}
</style>
